package name.wilbur.course.db.bigone.dao.impl;

import name.wilbur.course.db.bigone.dao.BaseDAO;
import name.wilbur.course.db.bigone.model.User;
import name.wilbur.course.db.bigone.util.Checker;

/**
 * @author wilbur
 */
public class UserDAO extends BaseDAO implements IUserDAO {
	public UserDAO() {
		super(User.class);
	}
	
	public User findByNameEmail(String value) {
		if (value == null)
			return null;
		User[] Users = (User[]) findWhere(" Name = '" + value + "'");
		if (Users == null) {
			Users = (User[]) findWhere(" Email = '" + value + "'");
			if (Users == null)
				return null;
		}
		return Users[0];
	}
	
	public User findByName(String name) {
		User[] users = null;
		if (Checker.notEmptyString(name)) {
			users = (User[]) findWhere(" Name = '" + name + "'");
		}
		if (users == null)
			return null;
		return users[0];
	}
	
	public User[] findAllUsersExcept(int userID) {
		String where_clause = primaryKey + " <> " + userID;
		return (User[]) findWhere(where_clause);
	}
}
